trigger preventDuplicateEmailForContact on Contact (before insert, before update) {
	
	if (UserInfo.getName() == 'Integration User')
  	{
  		return;
  	}
  			  	
	LINKSYS_SYS_PARAM__c sysParamObj = [Select VALUE__c from LINKSYS_SYS_PARAM__c
		Where   PARAM_NAME__c = 'PreventDuplicateEmailTrigger' ];

	string canRun = sysParamObj.VALUE__C.toUpperCase();
 
	if (canRun != 'ENABLED')
	{ 
		return;
	}
		    
	for (Contact c : Trigger.new) {
		Integer iDupeCount = 0;
        
        if (Trigger.isUpdate)
        {
            iDupeCount = [select count() from contact where email = :c.email and id <> :c.id];
        }
        else
        {
             iDupeCount = [select count() from contact where email = :c.email];
        }   
        
        if (iDupeCount > 0){
             c.addError('This email is already in use.  Please change the email address for this contact.');
        }           
    }

}